(function(){"use strict";BX.namespace("BX.Landing.UI.Panel");BX.Landing.UI.Panel.LinkButtons=function(t,e){BX.Landing.UI.Panel.BaseButtonPanel.apply(this,arguments);this.removeButton=new BX.Landing.UI.Button.Action("remove",{text:BX.message("LANDING_REMOVE_LINK"),onClick:this.onRemove.bind(this)});this.editButton=new BX.Landing.UI.Button.Action("edit",{text:BX.message("LANDING_EDIT_LINK"),onClick:this.onEdit.bind(this)});this.addButton(this.removeButton);this.addButton(this.editButton);document.body.appendChild(this.layout)};BX.Landing.UI.Panel.LinkButtons.getInstance=function(){if(!BX.Landing.UI.Panel.LinkButtons.instance){BX.Landing.UI.Panel.LinkButtons.instance=new BX.Landing.UI.Panel.LinkButtons("link_editor_buttons","landing-ui-panel-link-editor-buttons")}return BX.Landing.UI.Panel.LinkButtons.instance};BX.Landing.UI.Panel.LinkButtons.instance=null;BX.Landing.UI.Panel.LinkButtons.prototype={constructor:BX.Landing.UI.Panel.LinkButtons,__proto__:BX.Landing.UI.Panel.BaseButtonPanel.prototype,show:function(t){this.currentLink=t;var e=document.createRange();var n=window.scrollY;e.selectNode(this.currentLink);window.getSelection().removeAllRanges();window.getSelection().addRange(e);this.linkRect=t.getBoundingClientRect();requestAnimationFrame(function(){this.layout.style.position="fixed";this.layout.style.top=this.linkRect.bottom+n+"px";this.layout.style.left=this.linkRect.left+"px"}.bind(this));BX.Landing.UI.Panel.BaseButtonPanel.prototype.show.call(this)},onRemove:function(){document.execCommand("unlink",false);this.hide()},onEdit:function(t){t.preventDefault();t.stopPropagation();if(!this.editPanel){this.editPanel=new BX.Landing.UI.Panel.Content("create_link");this.editPanel.appendFooterButton(new BX.Landing.UI.Button.BaseButton("save_block_content",{text:BX.message("BLOCK_SAVE"),onClick:this.save.bind(this),className:"landing-ui-button-content-save"}));this.editPanel.appendFooterButton(new BX.Landing.UI.Button.BaseButton("cancel_block_content",{text:BX.message("BLOCK_CANCEL"),onClick:this.editPanel.hide.bind(this.editPanel),className:"landing-ui-button-content-cancel"}));document.body.appendChild(this.editPanel.layout)}BX.Landing.UI.Panel.EditorPanel.hide();BX.Landing.UI.Panel.SmallEditorPanel.hide();this.range=document.getSelection().getRangeAt(0);this.textNode=BX.Landing.Block.Node.Text.currentNode;this.textField=BX.Landing.UI.Field.BaseField.currentField;if(!!this.textField&&this.textField.isEditable()){this.textNode=this.textField}var e="LANDING_CREATE_LINK";if(this.range.toString()){e="LANDING_EDIT_LINK"}var n=new BX.Landing.UI.Form.BaseForm({title:BX.message(e)});var i=!!this.textNode.node?this.textNode.node.querySelector("a"):this.textNode.layout.querySelector("a");this.field=new BX.Landing.UI.Field.Link({text:this.range.toString(),href:!!i?i.getAttribute("href"):"",target:!!i?i.getAttribute("target"):""});var a=this.field;if(i){var o=i.getAttribute("href");if(o&&o.indexOf("{=")!==-1){BX.Landing.UI.Panel.URLList.getInstance().getEntries().then(function(t){t.forEach(function(t){var e="{=LANDING["+t.ID+"].URL}";if(o===e){a.hrefInput.setValue(BX.Landing.UI.Field.LinkURL.prototype.createPlaceholder(t.TITLE,t.ID,"LANDING"))}t.blocks.forEach(function(t){var e="{=BLOCK["+t.id+"].URL}";if(o===e){a.hrefInput.setValue(BX.Landing.UI.Field.LinkURL.prototype.createPlaceholder(t.name,t.id,"LANDING"))}})})})}}n.addField(this.field);this.editPanel.clear();this.editPanel.appendForm(n);this.editPanel.show();this.hide()},save:function(){document.getSelection().removeAllRanges();document.getSelection().addRange(this.range);this.textNode.enableEdit();document.execCommand("insertHTML",false,'<a href="'+this.field.getValue().href+'" target="'+this.field.getValue().target+'">'+this.field.getValue().text+"</a>");this.editPanel.hide()}}})();